/* @(#)GSAccountPricessor.java    V0.1
 *
 * Project: GS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   owen         2006-5-11
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.business;

import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;

import javax.servlet.ServletOutputStream;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;

import com.hitrust.gs.bean.GSPayReceiveAbleBean;
import com.hitrust.gs.dao.GSAccountDAO;
import com.hitrust.gs.dao.GSOrderDAO;
import com.hitrust.gs.dao.GSProviderDAO;
import com.hitrust.gs.form.GSAccountMonthForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.lib.GSSystemConfigurator;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.service.GSBaseManager;
import com.hitrust.gs.service.GSBaseProcesser;
import com.hitrust.gs.util.date.DateUtil;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.util.lang.StringUtils;
import com.hitrust.gs.vo.GSAccountMonthOfWorkingVO;
import com.hitrust.gs.vo.GSAccountMonthVO;
/**
 * 
 */
public class GSAccountProcessor implements GSBaseProcesser{
    /**
     * 取得本月对帐浏览信息
     * 
     * @param aGSOrderVO
     *            封装订单查询参数的VO对象
     * @return
     * @throws GSException
     */
    public ArrayList getAccountMonthList(GSAccountMonthVO aGSAccountMonthVO,ArrayList tOrg) throws GSException {
        ArrayList tAccountMonthList = new ArrayList();
        GSAccountDAO tGSAccountDAO = new GSAccountDAO();
        GSProviderDAO tPDAO = new GSProviderDAO();
        ArrayList tList = new ArrayList();
        Connection tConn = null;
        try {
            // 取得DB连接
            tConn = tGSAccountDAO.getConnetion();
            String[] tDateStr = new String[2];
            // 取得查询参数订单创建最小日期和最大日期
            tDateStr[0] = aGSAccountMonthVO.startdate;
            tDateStr[1] = aGSAccountMonthVO.enddate;
            // 格式化日期
            tDateStr = DateUtil.formateDate(tDateStr);
            aGSAccountMonthVO.startdate = tDateStr[0];
            aGSAccountMonthVO.enddate = tDateStr[1];
            String cczx = tPDAO.queryProvider(GSSystemConfigurator.getParam("gs.provider.cczxid")).getGs_provider_shortname();
            // 查询所有订单及明细
            tAccountMonthList = tGSAccountDAO.queryAccountMonth(tConn, aGSAccountMonthVO,tOrg,GSBaseConstants.TYPE_ORGA);
            if (tAccountMonthList.size() > 0) {
            
                for (int i = 0; i < tAccountMonthList.size(); i++) {

                    GSAccountMonthOfWorkingVO tGSAccountMonthOfWorkingVO = (GSAccountMonthOfWorkingVO) tAccountMonthList.get(i);
                     
                    // 判断新取得的OrderSubmitVO对象中的订单编号是否与前一对象中订单编号相同
                    // if(tOrderId.equals(tGSOrderSubmitVO.orderid)){
                    // 订单编号相同则将取得的产品信息放入同一订单VO对象的ArrayList对象中
                    // if(tConCentricityId.equals(tGSOrderSubmitVO.concentricityId)){
                    // continue;
                    // }
                    String[] tStr = new String[17];
                    tStr[0] = tGSAccountMonthOfWorkingVO.delivergoodsid;
                    tStr[1] = tGSAccountMonthOfWorkingVO.orgname;
                    if("0".equals(tGSAccountMonthOfWorkingVO.is_tradeflat_manufacture)){
                    	tStr[2] = cczx;
                    }else{
                    	tStr[2] = tGSAccountMonthOfWorkingVO.providerid;
                    }
                    
                    tStr[3] = tGSAccountMonthOfWorkingVO.concentricityid;
                    tStr[4] = tGSAccountMonthOfWorkingVO.manufacturename;
                    tStr[5] = tGSAccountMonthOfWorkingVO.manufacturespec;
                    tStr[6] = tGSAccountMonthOfWorkingVO.manufacturetype;
                    tStr[7] = tGSAccountMonthOfWorkingVO.manufacturebrand;
                    tStr[8] = tGSAccountMonthOfWorkingVO.manufacturername;
                    tStr[9] = StringUtils.formatEDouble(tGSAccountMonthOfWorkingVO.ordercount,2);
                    tStr[10]= StringUtils.formatEDouble(tGSAccountMonthOfWorkingVO.signincount,2);
                    tStr[11]= StringUtils.formatEDouble(tGSAccountMonthOfWorkingVO.goodsunitprice,4);
                    tStr[12]= tGSAccountMonthOfWorkingVO.signindate;
                    tStr[13]= tGSAccountMonthOfWorkingVO.signinperson;
                    tStr[14]= tGSAccountMonthOfWorkingVO.ordertempid;
                    tStr[15]= tGSAccountMonthOfWorkingVO.orderdetailid;
                    tStr[16]= tGSAccountMonthOfWorkingVO.quantunit;
                    
                    tList.add(tStr);
                    
                }
            }
        } catch (GSException ge) {
            throw ge;
        } catch (Exception e) {
            GSLogWriter.debug(this, e.toString());
            throw new GSException(GSException.E10041, GSException.E10041_MSG);
        } finally {
            GSOrderDAO.close(tConn);
        }
        return tList;
    }

    /**
     * 取得本月对帐浏览信息
     * 
     * @param aGSOrderVO
     *            封装订单查询参数的VO对象
     * @return
     * @throws GSException
     */
    public ArrayList getAccountMonthList4BusProv(GSAccountMonthVO aGSAccountMonthVO,ArrayList tOrg) throws GSException {
        ArrayList tAccountMonthList = new ArrayList();
        GSAccountDAO tGSAccountDAO = new GSAccountDAO();
        GSProviderDAO tPDAO = new GSProviderDAO();
        ArrayList tList = new ArrayList();
        Connection tConn = null;
        try {
            // 取得DB连接
            tConn = tGSAccountDAO.getConnetion();
            String[] tDateStr = new String[2];
            // 取得查询参数订单创建最小日期和最大日期
            tDateStr[0] = aGSAccountMonthVO.startdate;
            tDateStr[1] = aGSAccountMonthVO.enddate;
            // 格式化日期
            tDateStr = DateUtil.formateDate(tDateStr);
            aGSAccountMonthVO.startdate = tDateStr[0];
            aGSAccountMonthVO.enddate = tDateStr[1];
            String cczx = tPDAO.queryProvider(GSSystemConfigurator.getParam("gs.provider.cczxid")).getGs_provider_shortname();
            // 查询所有订单及明细
            tAccountMonthList = tGSAccountDAO.queryAccountMonth(tConn, aGSAccountMonthVO,tOrg,GSBaseConstants.TYPE_PROV);
            if (tAccountMonthList.size() > 0) {
            
                for (int i = 0; i < tAccountMonthList.size(); i++) {

                    GSAccountMonthOfWorkingVO tGSAccountMonthOfWorkingVO = (GSAccountMonthOfWorkingVO) tAccountMonthList.get(i);
                    // 判断新取得的OrderSubmitVO对象中的订单编号是否与前一对象中订单编号相同
                    // if(tOrderId.equals(tGSOrderSubmitVO.orderid)){
                    // 订单编号相同则将取得的产品信息放入同一订单VO对象的ArrayList对象中
                    // if(tConCentricityId.equals(tGSOrderSubmitVO.concentricityId)){
                    // continue;
                    // }
                    String[] tStr = new String[17];
                    tStr[0] = tGSAccountMonthOfWorkingVO.delivergoodsid;
                    tStr[1] = tGSAccountMonthOfWorkingVO.orgname;
                    if("0".equals(tGSAccountMonthOfWorkingVO.is_tradeflat_manufacture)){
                    	tStr[2] = cczx;
                    }else{
                    	tStr[2] = tGSAccountMonthOfWorkingVO.providerid;
                    }
                    tStr[3] = tGSAccountMonthOfWorkingVO.concentricityid;
                    tStr[4] = tGSAccountMonthOfWorkingVO.manufacturename;
                    tStr[5] = tGSAccountMonthOfWorkingVO.manufacturespec;
                    tStr[6] = tGSAccountMonthOfWorkingVO.manufacturetype;
                    tStr[7] = tGSAccountMonthOfWorkingVO.manufacturebrand;
                    tStr[8] = tGSAccountMonthOfWorkingVO.manufacturername;
                    tStr[9] = StringUtils.formatEDouble(tGSAccountMonthOfWorkingVO.ordercount,2);
                    tStr[10]= StringUtils.formatEDouble(tGSAccountMonthOfWorkingVO.signincount,2);
                    tStr[11]= StringUtils.formatEDouble(tGSAccountMonthOfWorkingVO.goodsunitprice,4);
                    tStr[12]= tGSAccountMonthOfWorkingVO.signindate;
                    tStr[13]= tGSAccountMonthOfWorkingVO.signinperson;
                    tStr[14]= tGSAccountMonthOfWorkingVO.ordertempid;
                    tStr[15]= tGSAccountMonthOfWorkingVO.orderdetailid;
                    tStr[16]= tGSAccountMonthOfWorkingVO.quantunit;
                    
                    tList.add(tStr);
                    
                }
            }
        } catch (GSException ge) {
            throw ge;
        } catch (Exception e) {
            GSLogWriter.debug(this, e.toString());
            throw new GSException(GSException.E10041, GSException.E10041_MSG);
        } finally {
            GSOrderDAO.close(tConn);
        }
        return tList;
    }

    /**
     * 本月对帐取得订单明细用于详细显示页面
     * @param aOrderId          订单编号
     * @return
     * @throws GSException
     */
//    public ArrayList getAccountDetail(String aOrderId) throws GSException{
//        ArrayList tRs = new ArrayList();
//        GSOrderDetailDAO tOrderDetailDAO = new GSOrderDetailDAO();
//        //查询SQL
//        StringBuffer tSql = new StringBuffer("select distinct a.GS_ORDER_DETAIL_ID as P1,a.GS_CONCENTRICITY_ID as P2,");
//        tSql.append("b.GS_MANUFACTURE_NAME as P3,b.GS_MANUFACTURE_SPEC as P4,b.GS_MANUFACTURE_TYPE as P5,");
//        tSql.append("b.GS_MANUFACTURE_BRAND as P6,c.GS_PROVIDER_SHORTNAME as P7,");
//        tSql.append("a.GS_ORDER_COUNT as P8,b.GS_QUANT_UNIT as P9,a.GS_GOODS_UNITPRICE as P10,");
//        tSql.append("a.GS_DELIVER_GOODS_DATE as P11,a.GS_DELIVER_GOODS_TIME as P12,a.GS_ORDER_DETAIL_STATUS as P13,");
//        tSql.append("a.GS_ORDER_TEMPID as P14,b.GS_IS_TRADEFLAT_MANUFACTURE as P15,c.GS_PROVIDER_ID as P16,");
//        tSql.append("c.GS_IS_TRADEFLAT_PROVIDER as P17,a.GS_SIGNIN_COUNT as P18,a.GS_SIGNIN_DATE as P19,a.GS_SIGNIN_PERSON as P20,a.GS_DELIVER_GOODS_ID as P21 ");
//        tSql.append("from GS_ORDER_DETAIL a,GS_MANUFACTURE b,GS_PROVIDER c ");
//        tSql.append("where a.GS_ORDER_TEMPID='"+aOrderId + "' and a.GS_CONCENTRICITY_ID=b.GS_CONCENTRICITY_ID ");
//        tSql.append("and c.GS_PROVIDER_ID=a.GS_PROVIDER_ID ");
//        tSql.append("and a.gs_manufacture_id=b.gs_manufacture_id ");
//        //执行查询
//        ArrayList tList = tOrderDetailDAO.queryOrderDetail(tSql.toString(),new GSOrderDetailOfBusVO());
//        if(tList.size() > 0){
//            //封装查询结果
//            for(int i=0; i<tList.size(); i++){
//                String tStr[] = new String[22];
//                GSOrderDetailOfBusVO tVO = (GSOrderDetailOfBusVO)tList.get(i);
//                tStr[0] = tVO.orderDetailId;
//                tStr[1] = tVO.conCentricityId;
//                tStr[2] = tVO.manufactureName;
//                tStr[3] = tVO.manufSpec;
//                tStr[4] = tVO.manufType;
//                tStr[5] = tVO.manufBrand;
//                tStr[6] = tVO.providerName;
//                tStr[7] = StringUtils.formatEDouble(tVO.orderCount,2);
//                tStr[8] = tVO.quantUnit;
//                tStr[9] = StringUtils.formatEDouble(tVO.goodUnitprice,4);
//                tStr[10] = StringUtils.formatEDouble(tVO.goodUnitprice * tVO.orderCount,4);
//                tStr[11] = tVO.deliverGoodsDate;
//                //System.out.print(tVO.deliverGoodsTime);
//                tStr[12] = GSBaseManager.getDeliverGoodsTime(tVO.deliverGoodsTime);
//                tStr[13] = GSBaseManager.getOrderDetailStatusName(tVO.orderDetailStatus);
//                tStr[14] = tVO.providerId;
//                tStr[15] = tVO.isTradeFlatManuf;
//                tStr[16] = tVO.isTradeFlatProvider;
//                tStr[17] = tVO.orderDetailStatus;
//                tStr[18] = StringUtils.formatEDouble(tVO.signincount,2);
//                tStr[19] = tVO.signdate;
//                tStr[20] = tVO.signinperson;
//                tStr[21] = tVO.delivergoodsid;
//                tRs.add(tStr);
//            }
//        }
//        return tRs;
//    }
    /**
     * 显示本公司及下属单位应付款项信息列表
     * @param tOrg
     * @return
     * @throws GSException
     */
    public ArrayList getPayAlertList(ArrayList tOrg) throws GSException{
        ArrayList tRs = new ArrayList();
        GSAccountDAO tGSAccountDAO = new GSAccountDAO();
        Connection tConn = null;
        try{
         // 取得DB连接
         tConn = tGSAccountDAO.getConnetion();
         ArrayList tPayAlertList=tGSAccountDAO.queryPayAlert(tConn,tOrg);
         if(tPayAlertList.size()>0){
            for (int i = 0; i < tPayAlertList.size(); i++) {
                GSPayReceiveAbleBean tGSPayReceiveAbleBean = (GSPayReceiveAbleBean) tPayAlertList.get(i);
                String[] tStr = new String[5];
                tStr[0]=GSBaseManager.getOrgNameByOrgId(tGSPayReceiveAbleBean.getGs_workcorp_id());
                tStr[1]=tGSPayReceiveAbleBean.getGs_fee_type_id();
                tStr[2]=StringUtils.formatEDouble(tGSPayReceiveAbleBean.getGs_balance_undone(),4);
                tStr[3]=tGSPayReceiveAbleBean.getGs_pay_date();
                tStr[4]=tGSPayReceiveAbleBean.getGs_principal();
                
                tRs.add(tStr);
            }
        }
        }
        catch (GSException ge) {
            throw ge;
        } catch (Exception e) {
            GSLogWriter.debug(this, e.toString());
            throw new GSException(GSException.E10041, GSException.E10041_MSG);
        } finally {
            GSAccountDAO.close(tConn);
        }
        return tRs;
    }
    
    /**
     * 把显示的列表导入成EXCEL
     * @param aGSAccountMonthVO
     * @param tOrg
     * @param tForm
     * @return
     * @throws GSException
     */
    public boolean exportAccountList(GSAccountMonthVO aGSAccountMonthVO,ArrayList tOrg,GSAccountMonthForm tForm,String tOrgID,int type) throws GSException{
        boolean tFlag = false;
        ArrayList tAccountMonthList = new ArrayList();
        GSAccountDAO tGSAccountDAO = new GSAccountDAO();
        ArrayList tList = new ArrayList();
        Connection tConn = null;
        try{
//          取得DB连接
            tConn = tGSAccountDAO.getConnetion();
            String[] tDateStr = new String[2];
            // 取得查询参数订单创建最小日期和最大日期
            tDateStr[0] = aGSAccountMonthVO.startdate;
            tDateStr[1] = aGSAccountMonthVO.enddate;
            // 格式化日期
            tDateStr = DateUtil.formateDate(tDateStr);
            aGSAccountMonthVO.startdate = tDateStr[0];
            aGSAccountMonthVO.enddate = tDateStr[1];
            tAccountMonthList = tGSAccountDAO.queryAccountMonth(tConn, aGSAccountMonthVO,tOrg,type);
            if(tAccountMonthList.size() >0){
                GSAccountMonthOfWorkingVO tGSAccountMonthOfWorkingVO = (GSAccountMonthOfWorkingVO)tAccountMonthList.get(0);
                //String tEndBalDate = DateUtil.splitSpecChar(tBean.getGs_end_date());
               // ArrayList tRs = tOrderDetailDAO.queryDetailAssociatedBalanced(aForm.getDeptId(),aForm.getDeptCategory(),tEndBalDate,aForm.getBalanceYM());
                //GSOrganizationDAO tOrgDAO = new GSOrganizationDAO();
                //String tName = tOrgDAO.queryOrgName(aForm.getDeptId());
                 writeFile(tAccountMonthList,tForm,aGSAccountMonthVO,tOrgID,type);
                tFlag = true;
            }else{
                GSLogWriter.error(this,GSException.E40005_MSG);
                throw new GSException(GSException.E40005,GSException.E40005_MSG);
            }
        }catch(GSException ge){
            throw ge;
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(e.toString());
        }finally {
            GSAccountDAO.close(tConn);
        }
        return tFlag;
    }
    
    /**
     * 把数据写入到EXCEL里面
     * @param tArrayList
     * @param aForm
     * @param aGSAccountMonthVO
     * @return
     * @throws GSException
     */
    private boolean writeFile(ArrayList tArrayList,GSBaseForm aForm,GSAccountMonthVO aGSAccountMonthVO,String tOrgID,int type)throws GSException{
        boolean result = true;
        try {
            HSSFWorkbook tWBook = new HSSFWorkbook();
            HSSFCellStyle tStyle = tWBook.createCellStyle();
            HSSFFont tFont = tWBook.createFont();
            
            HSSFSheet tSheet = tWBook.createSheet("1");
            HSSFRow tRow = tSheet.createRow(0);
            HSSFCell tCell = tRow.createCell((short)0);
            tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
            tCell.setCellType(HSSFCell.CELL_TYPE_STRING);
            
            tFont.setFontHeightInPoints((short)12);
            tFont.setColor(HSSFColor.GREEN.index);
            tStyle.setFont(tFont);
            tCell.setCellStyle(tStyle);
            String tDate = aGSAccountMonthVO.year + "年" + aGSAccountMonthVO.month + "月";
            String tDeptName=GSBaseManager.getOrgNameByOrgId(tOrgID);
            tCell.setCellValue(tDeptName + tDate + "对帐信息");

            
            tRow = tSheet.createRow(2);
            tCell = tRow.createCell((short)0);
            tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
            tCell.setCellValue("送货单号");
            tFont = tWBook.createFont();
            tFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            tStyle = tWBook.createCellStyle();
            tStyle.setFont(tFont);
            tCell.setCellStyle(tStyle);
            
            if(GSBaseConstants.TYPE_ORGA == type){
                tCell = tRow.createCell((short)1);
                tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
                tCell.setCellValue("订货单位");
                tFont = tWBook.createFont();
                tFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                tStyle = tWBook.createCellStyle();
                tStyle.setFont(tFont);
                tCell.setCellStyle(tStyle);
                
                tCell = tRow.createCell((short)2);
                tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
                tCell.setCellValue("供应商");
                tFont = tWBook.createFont();
                tFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                tStyle = tWBook.createCellStyle();
                tStyle.setFont(tFont);
                tCell.setCellStyle(tStyle);
            	
            }else{
                tCell = tRow.createCell((short)1);
                tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
                tCell.setCellValue("供应商");
                tFont = tWBook.createFont();
                tFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                tStyle = tWBook.createCellStyle();
                tStyle.setFont(tFont);
                tCell.setCellStyle(tStyle);
            	
                tCell = tRow.createCell((short)2);
                tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
                tCell.setCellValue("订货单位");
                tFont = tWBook.createFont();
                tFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                tStyle = tWBook.createCellStyle();
                tStyle.setFont(tFont);
                tCell.setCellStyle(tStyle);
                
            }

            tCell = tRow.createCell((short)3);
            tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
            tCell.setCellValue("集中编码");
            tFont = tWBook.createFont();
            tFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            tStyle = tWBook.createCellStyle();
            tStyle.setFont(tFont);
            tCell.setCellStyle(tStyle);

            tCell = tRow.createCell((short)4);
            tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
            tCell.setCellValue("产品名称");
            tFont = tWBook.createFont();
            tFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            tStyle = tWBook.createCellStyle();
            tStyle.setFont(tFont);
            tCell.setCellStyle(tStyle);

            tCell = tRow.createCell((short)5);
            tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
            tCell.setCellValue("规格");
            tFont = tWBook.createFont();
            tFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            tStyle = tWBook.createCellStyle();
            tStyle.setFont(tFont);
            tCell.setCellStyle(tStyle);
            
            tCell = tRow.createCell((short)6);
            tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
            tCell.setCellValue("型号");
            tFont = tWBook.createFont();
            tFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            tStyle = tWBook.createCellStyle();
            tStyle.setFont(tFont);
            tCell.setCellStyle(tStyle);
            
            tCell = tRow.createCell((short)7);
            tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
            tCell.setCellValue("品牌");
            tFont = tWBook.createFont();
            tFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            tStyle = tWBook.createCellStyle();
            tStyle.setFont(tFont);
            tCell.setCellStyle(tStyle);
            
            tCell = tRow.createCell((short)8);
            tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
            tCell.setCellValue("生产厂商");
            tFont = tWBook.createFont();
            tFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            tStyle = tWBook.createCellStyle();
            tStyle.setFont(tFont);
            tCell.setCellStyle(tStyle);
            
            tCell = tRow.createCell((short)9);
            tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
            tCell.setCellValue("签收数量");
            tFont = tWBook.createFont();
            tFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            tStyle = tWBook.createCellStyle();
            tStyle.setFont(tFont);
            tCell.setCellStyle(tStyle);
            
            tCell = tRow.createCell((short)10);
            tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
            tCell.setCellValue("价格");
            tFont = tWBook.createFont();
            tFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            tStyle = tWBook.createCellStyle();
            tStyle.setFont(tFont);
            tCell.setCellStyle(tStyle);
            
            tCell = tRow.createCell((short)11);
            tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
            tCell.setCellValue("总价");
            tFont = tWBook.createFont();
            tFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            tStyle = tWBook.createCellStyle();
            tStyle.setFont(tFont);
            tCell.setCellStyle(tStyle);

            tCell = tRow.createCell((short)12);
            tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
            tCell.setCellValue("签收日期");
            tFont = tWBook.createFont();
            tFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            tStyle = tWBook.createCellStyle();
            tStyle.setFont(tFont);
            tCell.setCellStyle(tStyle);
            
            tCell = tRow.createCell((short)13);
            tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
            tCell.setCellValue("签收人");
            tFont = tWBook.createFont();
            tFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            tStyle = tWBook.createCellStyle();
            tStyle.setFont(tFont);
            tCell.setCellStyle(tStyle);
            
            double index = 0;
            BigDecimal totalValue = new BigDecimal("0");
            BigDecimal providerValue = new BigDecimal("0");
            String lastOrz = "";
            GSProviderDAO tPDAO = new GSProviderDAO();
            String cczx = tPDAO.queryProvider(GSSystemConfigurator.getParam("gs.provider.cczxid")).getGs_provider_shortname();
            for(int i=0; i<tArrayList.size(); i++,index++){
                GSAccountMonthOfWorkingVO tVO = (GSAccountMonthOfWorkingVO)tArrayList.get(i);
                //如果是运营公司端程序，则需要预先将特约产品的原始供应商替换成仓储中心
                if(GSBaseConstants.TYPE_ORGA == type){
                	if("0".equals(tVO.is_tradeflat_manufacture))
                		tVO.providerid = cczx;
                }else{

                }
                String orzBuff = null;
                //如果是运营公司端程序，则需要为供应商的变化作判断
                if(GSBaseConstants.TYPE_ORGA == type){
                	orzBuff = tVO.providerid;
                }else{
                	orzBuff = tVO.orgname;
                }
                if(!lastOrz.equals(orzBuff) && i!=0){
                    tRow = tSheet.createRow((short)(3 + index));
                    tCell = tRow.createCell((short)13);
                    tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
                    tCell.setCellValue(lastOrz + ":" + StringUtils.fmtDbl(providerValue.toString(),2));
                    totalValue = providerValue.add(totalValue);
                    index++;
                    providerValue = new BigDecimal("0");
                }
                if(GSBaseConstants.TYPE_ORGA == type){
                	lastOrz = tVO.providerid;
                }else{
                	lastOrz = tVO.orgname;
                }
                
                tRow = tSheet.createRow((short)(3 + index));
                tCell = tRow.createCell((short)0); 
                tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
                tCell.setCellValue(tVO.delivergoodsid);
                
                if(GSBaseConstants.TYPE_ORGA == type){
                    tCell = tRow.createCell((short)1);
                    tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
                    tCell.setCellValue(tVO.orgname);
                    
                    tCell = tRow.createCell((short)2);
                    tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
                    tCell.setCellValue(tVO.providerid);
                	
                }else{
                    tCell = tRow.createCell((short)1);
                    tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
                    tCell.setCellValue(tVO.providerid);
                	
                    tCell = tRow.createCell((short)2);
                    tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
                    tCell.setCellValue(tVO.orgname);
                    
                }
                
                tCell = tRow.createCell((short)3);
                tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
                tCell.setCellValue(tVO.concentricityid);
                
                tCell = tRow.createCell((short)4);
                tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
                tCell.setCellValue(tVO.manufacturename);
                
                tCell = tRow.createCell((short)5);
                tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
                tCell.setCellValue(tVO.manufacturespec);
                
                tCell = tRow.createCell((short)6);
                tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
                tCell.setCellValue(tVO.manufacturetype);
                
                tCell = tRow.createCell((short)7);
                tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
                tCell.setCellValue(tVO.manufacturebrand);
                
                tCell = tRow.createCell((short)8);
                tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
                tCell.setCellValue(tVO.manufacturername);
                tStyle = tWBook.createCellStyle();
                tCell.setCellStyle(tStyle);
                
                tCell = tRow.createCell((short)9);
                tCell.setCellValue(tVO.signincount);
                tStyle = tWBook.createCellStyle();
                tStyle.setDataFormat(tWBook.createDataFormat().getFormat("0.00"));
                tCell.setCellStyle(tStyle);

                tCell = tRow.createCell((short)10);
                tCell.setCellValue(tVO.goodsunitprice);
                tStyle = tWBook.createCellStyle();
                tStyle.setDataFormat(tWBook.createDataFormat().getFormat("0.0000"));
                tCell.setCellStyle(tStyle);
                
                tCell = tRow.createCell((short)11);
                BigDecimal buffer = new BigDecimal(Double.toString(tVO.goodsunitprice)).multiply(new BigDecimal(Double.toString(tVO.signincount)));
                tCell.setCellValue(buffer.toString());
                tStyle = tWBook.createCellStyle();
                tStyle.setDataFormat(tWBook.createDataFormat().getFormat("0.0000"));
                tCell.setCellStyle(tStyle);
                
                tCell = tRow.createCell((short)12);
                tCell.setCellValue(tVO.signindate);
                tStyle = tWBook.createCellStyle();
                tCell.setCellStyle(tStyle);
                
                tCell = tRow.createCell((short)13);
                tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
                tCell.setCellValue(tVO.signinperson);
                tStyle = tWBook.createCellStyle();
                tCell.setCellStyle(tStyle);
                
                providerValue = new BigDecimal(Double.toString(tVO.signincount)).multiply(new BigDecimal(Double.toString(tVO.goodsunitprice))).add(providerValue);
            }
            //最后一行合计
            tRow = tSheet.createRow((short)(3 + index));
            tCell = tRow.createCell((short)13);
            tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
            tCell.setCellValue(lastOrz + ":" + StringUtils.fmtDbl(providerValue.toString(),2));
            tStyle = tWBook.createCellStyle();
            tCell.setCellStyle(tStyle);
            totalValue = totalValue.add(providerValue);
            //总计
            tRow = tSheet.createRow((short)(3 + index + 1));
            tCell = tRow.createCell((short)13);
            tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
            tCell.setCellValue("总计:"+StringUtils.fmtDbl(totalValue.toString(),2));
            tStyle = tWBook.createCellStyle();
            tCell.setCellStyle(tStyle);
            
            
            String aPath =  aGSAccountMonthVO.year + aGSAccountMonthVO.month +"AccountList" ;
            aForm.getResponse().setContentType("application/ms-excel");
            aForm.getResponse().setHeader("Content-Disposition",
                    "attachment;filename=" + aPath +".xls");
            ServletOutputStream tOutStream = aForm.getResponse().getOutputStream();
            tWBook.write(tOutStream);
            tOutStream.flush();
            tOutStream.close();
        } catch (Exception e) {
            e.printStackTrace();
            result = false;
            throw new GSException(e.toString());
        } finally {

        }
        return result;
    }
}
